<template>
  <div class="assets_wrap">
    <div class="login_assets" v-if="userInfo.isLogin">
      <div class="assets_preview flex">
        <div class="total_assets flex_one" :class="{'private': !show, 'public':show}">
          <p>
            <span class="text">总资产(元)</span>
            <i class="eye_icon" @click="toggle"></i>
          </p>
          <p class="preview_num">{{assetsInfo.asset_balance | numberComma}}</p>
        </div>
        <div class="yest_earn flex_one">
          <p class="text">昨日收益</p>
          <p class="preview_num">{{assetsInfo.fetch_balance | numberComma}}</p>
        </div>
        <router-link class="arrow-right" to="/dz-mall/otc/front/userCenter/finan"></router-link>
      </div>
      <div class="assets_detail flex" :class="{'expanded': expand}">
        <ul class="assets_detail_left w50">
          <li class="flex">
            <p class="assets_name">基金</p>
          </li>
          <li class="flex">
            <p class="assets_total">{{calcFormat(assetsInfo.fetch_balance)}}</p>
            <p class="earn_yest">{{calcFormat(assetsInfo.fetch_balance)}}</p>
          </li>
        </ul>
        <ul class="assets_detail_right w50">
          <li class="flex">
            <p class="assets_name">其他理财</p>
          </li>
          <li class="flex">
            <p class="assets_total">{{calcFormat(assetsInfo.fetch_balance)}}</p>
            <p class="earn_yest">{{calcFormat(assetsInfo.fetch_balance)}}</p>
          </li>
        </ul>
      </div>
      <div class="assets_icon_wrap" @click="toggleExpand">
        <div class="asset_icon_bg"></div>
        <i class="assets_icon" :class="{'expanded': expand}"></i>
      </div>
    </div>
    <div class="login_assets" v-else>
      <div class="assets_preview flex">
        <div class="total_assets flex_one" :class="{'private': !show, 'public':show}">
          <p><span class="text">总资产(元)</span></p>
          <p><router-link class="login" to="/dz-mall/otc/front/login" replace>登录查看</router-link></p>
        </div>
        <div class="yest_earn flex_one">
          <p class="text">昨日收益</p>
          <p class="preview_num">- -</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';

export default {
  name: 'Assets',
  computed: mapState(['assetsInfo', 'userInfo']),
  data() {
    return {
      show: true, // 默认隐藏资产信息
      expand: true, // 默认展开资产信息
    };
  },
  mounted() {
    // console.log('userInfo', this.userInfo.userInfo);
    // console.log('assetsInfo', this.assetsInfo);
  },
  methods: {
    toggle() {
      this.show = !this.show;
    },
    toggleExpand() {
      this.expand = !this.expand;
    },
    calcFormat(num) {
      return this.show ? num : '****';
    }
  }
};
</script>

<style lang="less" scoped>
.assets_wrap {
  font-size: 12px;
  color: #fff;
  background-color: #1f6aff;
  position: relative;
  .assets_preview {
    padding: 0 20px 10px 15px;
    line-height: 28px;
    position: relative;
    .arrow-right {
      width: 18px;
      height: 18px;
      background: url('../assets/images/icon/icon_common_arrow@2x.png') no-repeat;
      background-size: contain;
      display: inline-block;
      position: absolute;
      right: 0;
      top: calc(50% - 9px);
    }
    .total_assets {
      text-align: left;
      .eye_icon {
        width: 24px;
        height: 24px;
        display: inline-block;
        background-size: contain;
        margin-left: 8px;
        vertical-align: middle;
      }
      &.public{
        .eye_icon {
          background-image: url("../assets/images/icon_common_open@2x.png");
        }
      }
      &.private{
        .eye_icon {
          background-image: url("../assets/images/icon_common_hide@2x.png");
        }
      }
    }
    .yest_earn {
      text-align: right;
    }
    .text {
      opacity: 0.5;
      letter-spacing: 0.52px;
    }
    .preview_num {
      font-size: 24px;
      line-height: 36px;
    }
    .login{
      font-size: 20px;
      color: #fff;
      font-weight: bold;
    }
  }
  .assets_detail {
    line-height: 35px;
    text-align: left;
    padding-bottom: 0;
    max-height: 0;
    overflow-y: hidden;
    transition: maxHeight, paddingBottom 2.5s linear 0s;
    &.expanded{
      max-height: 70px;
      padding-bottom: 20px;
      transition: maxHeight, paddingBottom 2.5s linear 0s;
    }
    p {
      display: inline-block;
    }
    .earn_yest {
      text-align: right;
      padding-right: 10px;
    }
    .assets_detail_left .flex{
      margin-right: 1px;
      .assets_name {
        opacity: 0.6;
        padding-left: 15px;
      }
      .assets_total {
        padding-left: 15px;
      }
    }
    .assets_detail_right .flex{
      .assets_name {
        opacity: 0.6;
        padding-left: 8px;
      }
      .assets_total {
        padding-left: 8px;
      }

    }
    .assets_detail_left .flex, .assets_detail_right .flex {
      margin-bottom: 1px;
      background-color: rgba(0, 0, 0, 0.05);
    }
  }
  .assets_icon_wrap {
    height: 20px;
    width: 100%;
    position: absolute;
    left: 0;
    bottom: 0;
    .asset_icon_bg {
      height: 100%;
      background-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0) 100%);
      opacity: 0.05;
      transform: scaleY(-1);
    }
    .assets_icon {
      position: absolute;
      top: 8px;
      left: 50%;
      transform: translate(-6px, 0);
      width: 0;
      height: 0;
      border-width: 6px;
      border-style: solid;
      border-color: #dbdbdb transparent transparent transparent;
      display: block;
    }
    .assets_icon.expanded {
      top: 0px;
      border-color: transparent transparent #dbdbdb transparent;
    }
  }
  .assets_right {
    text-align: right;
    vertical-align: middle;
    .lc-btn {
      font-size: 13px;
      color: #fff;
    }
  }
}
</style>